using System;
using GameFrameworkLibraly.BaseObjects;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameFrameworkLibraly.Controls
{
    public class RadioButtonControl:CheckableControl
    {
        /// <summary>
        /// Creates a new instance of radio button
        /// </summary>
        /// <param name="game">Current game</param>
        /// <param name="destinationRectangle">Defines rectangle where the control must be drawn</param>
        /// <param name="checkedTexture">Texture that will be drawn when checkbox is checked</param>
        /// <param name="uncheckedTexture">Texture that will be drawn when checkbox isn't checked</param>
        public RadioButtonControl(MyGame game, Rectangle destinationRectangle, Texture2D checkedTexture, Texture2D uncheckedTexture)
            : base(game, destinationRectangle, checkedTexture, uncheckedTexture)
        {
            Released += RadioButtonControlReleased;
            Tapped += RadioButtonControlTapped;
        }

        /// <summary>
        /// Creates a new instance of radio button
        /// </summary>
        /// <param name="game">Current game</param>
        /// <param name="destinationRectangle">Defines rectangle where the control must be drawn</param>
        /// <param name="checkedTexture">Texture that will be drawn when checkbox is checked</param>
        /// <param name="uncheckedTexture">Texture that will be drawn when checkbox isn't checked</param>
        /// <param name="text">Text that will be printed near checkbox</param>
        /// <param name="spriteFont">SpriteFont that will be used to print text</param>
        public RadioButtonControl(MyGame game, Rectangle destinationRectangle, Texture2D checkedTexture, Texture2D uncheckedTexture, string text, SpriteFont spriteFont)
            : base(game, destinationRectangle, checkedTexture, uncheckedTexture, text, spriteFont)
        {
            Released += RadioButtonControlReleased;
            Tapped += RadioButtonControlTapped;
        }

        void RadioButtonControlTapped(object sender, EventArgs e)
        {
            Checked = true;
        }

        /// <summary>
        /// Sets the checked without fireing an event;
        /// </summary>
        /// <param name="state">state</param>
        public void SetItemChecked(bool state)
        {
            CheckedField = state;
        }


        void RadioButtonControlReleased(object sender, EventArgs e)
        {
            Checked = true;
        }
    }
}
